﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using System.Collections.Generic;
using WinAutomator.Library;

namespace WinAutomator.ViewModel
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// See http://www.galasoft.ch/mvvm
    /// </para>
    /// </summary>
    public class ToolBoxViewModel : ViewModelBase
    {
        /// <summary>
        /// Initializes a new instance of the ToolBoxViewModel class.
        /// </summary>
        public ToolBoxViewModel()
        {
            _plugins = PluginManager.Instance.Plugins;
        }

        /// <summary>
        /// The <see cref="Plugins" /> property's name.
        /// </summary>
        public const string PluginsPropertyName = "Plugins";

        private List<IPlugin> _plugins = null;

        /// <summary>
        /// Sets and gets the Plugins property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public List<IPlugin> Plugins
        {
            get
            {
                if (ViewModelBase.IsInDesignModeStatic)
                {

                }
                return PluginManager.Instance.Plugins;
            }

            set
            {
                if (_plugins == value)
                {
                    return;
                }

                RaisePropertyChanging(PluginsPropertyName);
                _plugins = value;
                RaisePropertyChanged(PluginsPropertyName);
            }
        }

        /// <summary>
        /// The <see cref="SelectedItem" /> property's name.
        /// </summary>
        public const string SelectedItemPropertyName = "SelectedItem";

        private IPlugin _selectedItem = null;

        /// <summary>
        /// Sets and gets the SelectedItem property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public IPlugin SelectedItem
        {
            get
            {
                return _selectedItem;
            }

            set
            {
                if (_selectedItem == value)
                {
                    return;
                }

                _selectedItem = value;
                RaisePropertyChanged(SelectedItemPropertyName);
                Messenger.Default.Send(_selectedItem, "SelectPluginToolBox");
            }
        }
    }
}